Socket
Socket
Sign inDemoInstall

@rescui/use-resize-observer

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rescui/use-resize-observer

ResizeObserver hook


Version published
Weekly downloads
1.5K
decreased by-17.42%
Maintainers
0
Weekly downloads
 
Created
Source

ResizeObserver hook

This package is used for observing react elements. It uses ResizeObserver and alleviates some of its bugs.

It's best used together with React refs. It can be used with raw HTML elements, although it's better to avoid that.

Usage examples

React ref example

import React, { useRef } from 'react';
import { useResizeObserver } from '@rescui/use-resize-observer';

const MyComponent = () => {
  const ref = useRef<HTMLElement>(null);
  useResizeObserver(ref, (entry: ResizeObserverEntry) => {
    // resize logic
  });

  return <div ref={ref}>To the moon!</div>;
};

HTML element example

Note: Avoid this option when possible due to additional re-renders when using callback refs and useState. Use React ref instead.

import React, { useState } from 'react';
import { useResizeObserver } from '@rescui/use-resize-observer';

const MyComponent = () => {
  const [el, setEl] = useState<HTMLElement>(null);
  useResizeObserver(el, (entry: ResizeObserverEntry) => {
    // resize logic
  });

  return <div ref={setEl}>To the moon!</div>;
};

FAQs

Package last updated on 15 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc